package com.gxa.admin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.admin.mapper.EmployeeMapper;
import com.gxa.admin.pojo.dto.EmployeeDto;
import com.gxa.admin.service.EmployeeService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.pojo.TEmployee;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @description
 * @author: RicksonYu
 * @create: 2024年-03月-20日--18:12
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;
    @Override
    public QueryResult queryAll(EmployeeDto employeeDto) {

        //分页查询
       // Page<TEmployee> page = new Page<>(employeeDto.getPage(), employeeDto.getLimit());
        Page<TEmployee> page = PageHelper.startPage(employeeDto.getPage(), employeeDto.getLimit());
        //查询所有人员
        List<TEmployee> tEmployeeList = employeeMapper.queryAllEmployee(employeeDto);

        //封装返回数据
        QueryResult queryResult = new QueryResult();
        queryResult.setData(tEmployeeList);
        queryResult.setCount(page.getTotal());

        return queryResult;
    }

    //具体添加

    @Override
    public int addEmployee(EmployeeDto employeeDto) {

        int i = employeeMapper.saveEmployee(employeeDto);
        System.out.println("侦测到----"+i);
        return i;
        //return employeeMapper.saveEmployee(employeeDto);


    }

    @Override
    public int updateEmploy(EmployeeDto employeeDto) {


        return employeeMapper.editEmploy(employeeDto);

    }

    @Override
    public void deleteBannerById(String id) {

            employeeMapper.deleteBy(id);
    }
}
